package com.testplatform.aitestplatform.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.testplatform.common.annotation.Log;
import com.testplatform.common.core.controller.BaseController;
import com.testplatform.common.core.domain.AjaxResult;
import com.testplatform.common.core.domain.R;
import com.testplatform.common.core.page.TableDataInfo;
import com.testplatform.common.enums.BusinessType;
import com.testplatform.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.testplatform.aitestplatform.domain.ApiTestCase;
import com.testplatform.aitestplatform.service.IApiTestCaseService;


/**
 * 接口自动化测试用例Controller
 * 
 * @author ruoyi
 * @date 2025-10-26
 */
@Api("接口自动化测试用例管理")
@RestController
@RequestMapping("/aitestplatform/case")
public class ApiTestCaseController extends BaseController
{
    @Autowired
    private IApiTestCaseService apiTestCaseService;

    /**
     * 查询接口自动化测试用例列表
     */
    @ApiOperation("查询接口自动化测试用例列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("查询条件对象") ApiTestCase apiTestCase)
    {
        startPage();
        List<ApiTestCase> list = apiTestCaseService.selectApiTestCaseList(apiTestCase);
        return getDataTable(list);
    }

    /**
     * 导出接口自动化测试用例列表
     */
    @ApiOperation("导出接口自动化测试用例列表")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:export')")
    @Log(title = "接口自动化测试用例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam("导出的查询条件") HttpServletResponse response, ApiTestCase apiTestCase)
    {
        List<ApiTestCase> list = apiTestCaseService.selectApiTestCaseList(apiTestCase);
        ExcelUtil<ApiTestCase> util = new ExcelUtil<ApiTestCase>(ApiTestCase.class);
        util.exportExcel(response, list, "接口自动化测试用例数据");
    }

    /**
     * 获取接口自动化测试用例详细信息
     */
    @ApiOperation("获取接口自动化测试用例详细信息")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:query')")
    @GetMapping(value = "/{id}")
    public R<ApiTestCase> getInfo(@PathVariable("id") @ApiParam("接口自动化测试用例ID") Long id)
    {
        return R.ok(apiTestCaseService.selectApiTestCaseById(id));
    }

    /**
     * 新增接口自动化测试用例
     */
    @ApiOperation("新增接口自动化测试用例")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:add')")
    @Log(title = "接口自动化测试用例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @ApiParam("新增的接口自动化测试用例对象") ApiTestCase apiTestCase)
    {
        return toAjax(apiTestCaseService.insertApiTestCase(apiTestCase));
    }

    /**
     * 修改接口自动化测试用例
     */
    @ApiOperation("修改接口自动化测试用例")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:edit')")
    @Log(title = "接口自动化测试用例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @ApiParam("修改的接口自动化测试用例对象") ApiTestCase apiTestCase)
    {
        return toAjax(apiTestCaseService.updateApiTestCase(apiTestCase));
    }

    /**
     * 删除接口自动化测试用例
     */
    @ApiOperation("删除接口自动化测试用例")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:remove')")
    @Log(title = "接口自动化测试用例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable @ApiParam("要删除的接口自动化测试用例ID") Long[] ids)
    {
        return toAjax(apiTestCaseService.deleteApiTestCaseByIds(ids));
    }

    @ApiOperation("执行接口自动化测试用例")
    @PreAuthorize("@ss.hasPermi('aitestplatform:case:remove')")
    @PostMapping("/executionApiTestCase")
    public R<Integer> executionApiTestCase(ApiTestCase apiTestCase)
    {
        int i =  apiTestCaseService.executionApiTestCase(apiTestCase);
        return R.ok(i);
    }
}
